package com.dmall.rpc.consumer;

import com.dmall.rpc.client.RpcProxy;
import com.dmall.rpc.service.PersonService;
import com.dmall.rpc.service.Person;
import com.dmall.rpc.service.Student;
import com.dmall.rpc.service.StudentService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * 单元测试
 * @author xiao1.wang@damll.com
 * @date 2019-12-27 17:00:12
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring.xml")
public class HelloActionTest {

	@Autowired
	private RpcProxy rpcProxy;
	
	@Test
	public void test1() {
		// 调用代理的create方法，代理HelloService接口
		PersonService helloService = rpcProxy.create(PersonService.class);
		
		// 调用代理的方法，执行invoke
		String result = helloService.getPersonName(1);
		System.out.println("服务端返回结果：");
		System.out.println(result);
	}

	@Test
	public void test2() {
		PersonService helloService = rpcProxy.create(PersonService.class);
		Person person  = helloService.getPerson(new Person(1, "zhangsan", 20));
		System.out.println("服务端返回结果：");
		System.out.println(person);
	}

	@Test
	public void test3() {
		PersonService helloService = rpcProxy.create(PersonService.class);
		List<Person> personList = helloService.getPersonList();
		System.out.println("服务端返回结果：");
		System.out.println(personList);
	}

	@Test
	public void test4() {
		StudentService studentService = rpcProxy.create(StudentService.class);
		List<Student> studentList = studentService.getStudentList("zhangsan", 20);
		System.out.println(studentList);
	}
}
